import { createApp } from 'vue'
import router from './router'
import store from './store'
import './style.css'
import App from './App.vue'
import axios from 'axios'
import 'cherry-markdown/dist/cherry-markdown.css'

axios.defaults.baseURL = 'http://api.vikingship.xyz/api'
axios.interceptors.request.use(config => {
  config.params = {
    ...config.params,
    icode: 'B2A3EDF71615F91F'
  }
  // 如果是上传文件，添加到 FormData 中
  if (config.data instanceof FormData) {
    config.data.append('icode', 'B2A3EDF71615F91F')
  } else {
  // 普通的 body 对象，添加到 data 中
    config.data = { ...config.data, icode: 'B2A3EDF71615F91F' }
  }
  store.commit('setLoading', true)
  store.commit('setError', { status: false, message: '' })
  return config
})
axios.interceptors.response.use(config => {
  store.commit('setLoading', false)
  return config
}, e => {
  const { error } = e.response.data
  store.commit('setError', { status: true, message: error || '请求错误' })
  store.commit('setLoading', false)
  return Promise.reject(error)
}
)
const app = createApp(App)
app.use(router).use(store)
.mount('#app')
